home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Text / Edit / GoldED-Demo / installdata / golded / developer / scanner / examples / c / c.c
Encoding:
C/C++ Source or Header  |  1999-12-03  |  1.5 KB  |  62 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for C functions.
  4.   
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.  
  9.   DICE:
  10.   
  11.   dcc c.c -// -l0 -md -mRR -o golded:etc/scanner/c
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. ULONG
  19. ScanHandlerC(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  20. {
  21.     const char *version = "$VER: C 1.0 (" __COMMODORE_DATE__ ")";
  22.  
  23.     if (len) {
  24.  
  25.         UBYTE *from = *text;
  26.  
  27.         if (*from != 32) {
  28.  
  29.             UBYTE *last;
  30.  
  31.             for (last = from + len - 1; len && (*last == 32); --len)
  32.                 --last;
  33.  
  34.             if ((*last == ')') && (((*from >= 'A') && (*from <= 'Z')) || ((*from >= 'a') && (*from <= 'z')))) {
  35.  
  36.                 UBYTE *nextChar;
  37.                 UWORD  words;
  38.  
  39.                 for (words = 0, nextChar = from; nextChar < last; ++nextChar) {
  40.  
  41.                     if (*nextChar == '(') {
  42.  
  43.                         *text = from;
  44.  
  45.                         return((ULONG)(nextChar - from));
  46.                     }
  47.                     else if (*nextChar < '0') {
  48.  
  49.                         from = nextChar + 1;
  50.  
  51.                         if (++words > 3)
  52.                             break;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.     }
  58.  
  59.     return(FALSE);
  60. }
  61.  
  62.